<template>
	<view v-if="pageShow">
		<view class="mainpadding" style="padding-bottom: 150rpx;">
			<view class="flexbetween">
				<view class="hong_text main_size bold">
					<text style="font-size: 40rpx;color: #019891;margin-right: 10rpx;" class="bold"
						v-if="orderInfo.ordergood.order_type==3">時</text>
					排號：{{orderInfo.call_no}}
				</view>
				<view class="hong_text main_size" v-show="orderInfo.status==0">未到店</view>
				<view class="lv_text main_size" v-show="orderInfo.status==1">已到店</view>
				<view class="huang_text main_size" v-show="orderInfo.status==2 && orderInfo.desk!=-1">
					{{orderInfo.desk}}
				</view>
				<view class="hui_text main_size" v-show="orderInfo.status==88">用戶取消</view>
				<view class="lv_text main_size" v-show="orderInfo.status==99">已完成</view>
			</view>

			<view class="mainpadding_top ffffff radius">
				<view class="hei_text main_size bold">客戶名稱：{{orderInfo.username}}</view>
				<view class="flexleft margin_top">
					<view class="hui_text main_size bold">客戶電話：{{maskMiddle(orderInfo.phone)}}</view>
					<view class="copyimg" @click="copy(orderInfo.phone)"></view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.image">
					<view class="xiaohei main_size">支付憑證</view>
					<image class="listleftimg1 radius" :src="orderInfo.image_text" mode=""
						@click.stop="lbtpriview(0,[orderInfo.image_text])"></image>
				</view>
				<view class="hui_text margin_top main_size bold" v-if="orderInfo.ordergood.order_type!=3">
					客戶人數：大人{{orderInfo.crnum}}人，老人{{orderInfo.oldnum}}人，兒童{{orderInfo.ernum}}人，共{{orderInfo.ernum+orderInfo.oldnum+orderInfo.crnum}}人
				</view>
				<view class="hui_text margin_top main_size bold" v-if="orderInfo.ordergood.order_type==3">
					客戶人數：<text v-for="(item,index) in cdbjhsf_data" :key="index">
						<text v-if="item.num!=0" class="margin_right1"><text
								class="huang_text">{{item.num}}</text>/{{item.name}}</text>
					</text>
				</view>
				<view class="huang_text margin_top main_size bold">預約時間：{{orderInfo.yuefenzu}} {{orderInfo.yuetime}}</view>
				<view class="lv_text margin_top main_size bold" v-show="orderInfo.status==99">
					完成時間：{{secondDate(orderInfo.updatetime,0,0)}}</view>
				<view class="hong_text margin_top main_size bold" v-show="orderInfo.status==88">
					取消時間：{{secondDate(orderInfo.updatetime,0,0)}}</view>
			</view>
			<view class="mainpadding_top ffffff radius" v-if="orderInfo.ordergood.ordergoodslist.length">
				<view class="xiaohei main_size">已選商品</view>
				<view class="padding_top3 line_top margin_top">
					<view class="flexbetween">
						<view class="text_a color_ling">訂單編號：{{orderInfo.ordergood.order_sn}}</view>
						<view class="text_x color_red">#{{orderInfo.ordergood.id}}</view>
					</view>
					<view class="flexleft margin_top" v-for="(ite,inde) in orderInfo.ordergood.ordergoodslist"
						:key="inde">
						<view class="goodsImg margin_right3">
							<image :src="ite.logoimage_text" mode=""></image>
						</view>
						<view class="justify_between_column" style="height: 157rpx;width: 100%;">
							<view class="text_a color_san bold">{{ite.goods_name}}</view>
							<view class="text_b color_six flexbetween margin_top1" v-if="ite.wei || ite.hei">
								<text>尺寸：{{ite.wei}}*{{ite.hei}}</text>
								<text>用量：{{ite.formulacount}}{{ite.size}}</text>
							</view>
							<view class="xiaolan" v-if="ite.spunatdata_text && ite.spunatdata_text.length">規格：<text class="margin_right1"
									v-for="(value) in ite.spunatdata_text"
									:key="value.spunatid">{{value.spunatname}}*{{value.num}}&nbsp;&nbsp;&nbsp;</text>
							</view>
							<!-- <view class="text_b color_six" v-show="ite.spunatname">規格：{{ite.spunatname}}</view> -->
							<view class="flexbetween margin_top1">
								<view class="price xiaohuang">${{ite.d_price}}&nbsp;&nbsp;&nbsp;x{{ite.num}}</view>
								<view class="text_six xiaohuang color_orange">${{ite.price}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="titletext hei_text bold">發票信息</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size">類型</view>
					<view class="hui_text main_size" v-if="orderInfo.opentype==0">紙本</view>
					<view class="hui_text main_size" v-if="orderInfo.opentype==1">載具</view>
					<view class="hui_text main_size" v-if="orderInfo.opentype==2">統編</view>
					<view class="hui_text main_size" v-if="orderInfo.opentype==3">捐贈</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.opentype!=0 && orderInfo.user">
					<view class="hei_text main_size" v-if="orderInfo.opentype==1">手機載具</view>
					<view class="hei_text main_size" v-if="orderInfo.opentype==2">統一編碼</view>
					<view class="hei_text main_size" v-if="orderInfo.opentype==3">捐贈碼</view>
					<view class="xiaolan bold main_size" v-if="orderInfo.opentype==1">{{orderInfo.user.zjcode}}</view>
					<view class="xiaolan bold main_size" v-if="orderInfo.opentype==2">{{orderInfo.user.tbcode}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.opentype==2">
					<view class="hei_text main_size" v-if="orderInfo.tbmc">發票抬頭 </view>
					<view class="hui_text main_size" v-if="orderInfo.tbmc">{{orderInfo.tbmc}}</view>
				</view>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="flexbetween " v-if="orderInfo.ordergood.order_sn">
					<view class="hei_text main_size bold">訂單編號</view>
					<view class="hui_text main_size bold">{{orderInfo.ordergood.order_sn}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.createtime">
					<view class="hei_text main_size bold">下單時間</view>
					<view class="hui_text main_size bold">{{secondDate(orderInfo.createtime,0,0)}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.order_type==3">
					<view class="hei_text main_size bold">人數基本價</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.rs_price}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.order_type==3">
					<view class="hei_text main_size bold">商品總金額</view>
					<view class="huang_text main_size bold">
						${{Number(orderInfo.ordergood.countmoney)-Number(orderInfo.ordergood.rs_price)-Number(orderInfo.ordergood.fw_price)}}
					</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.order_type==3">
					<view class="hei_text main_size bold">服務費用</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.fw_price}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size bold">總金額</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.countmoney || 0}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size bold">已付金額</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.paymoney || 0}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size bold">未付金額</view>
					<view class="hong_text main_size bold">${{orderInfo.ordergood.zhuimoney || 0}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.paytype!=0">
					<view class="hei_text main_size bold">支付方式</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==1">點數支付</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==2">多元支付</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==3">現金支付</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==4">信用卡</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==5">Line Pay線上支付
					</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==6">街口線上支付
					</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==7">街口線下支付
					</view>
					<view class="hui_text main_size bold" v-if="orderInfo.ordergood.paytype==8">Line Pay線下支付
					</view>
					<view class="hui_text main_size bold" v-show="orderInfo.ordergood.paytype==9">Line Pay二維碼支付
					</view>
					<view class="hui_text main_size bold" v-show="orderInfo.ordergood.paytype==10">街口二維碼支付
					</view>
					<view class="hui_text main_size bold" v-show="orderInfo.ordergood.paytype==11">全支付線下支付
					</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size bold">{{returnzftext(orderInfo.ordergood.paytype)}}</view>
					<view class="hui_text main_size bold">${{orderInfo.ordergood.paymoney}}</view>
				</view>
				<template v-if="orderInfo.ordergood.paytype==6 || orderInfo.ordergood.paytype==7">
					<view class="flexbetween margin_top">
						<view class="hei_text main_size bold">街口券折抵 </view>
						<view class="hui_text main_size bold">${{orderInfo.RedeemAmount}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="hei_text main_size bold">街口幣折抵 </view>
						<view class="hui_text main_size bold">${{orderInfo.StoreRedeemAmount}}</view>
					</view>
				</template>
				<template v-if="orderInfo.ordergood.paytype==5 || orderInfo.ordergood.paytype==8">
					<view class="flexbetween margin_top">
						<view class="hei_text main_size bold">LINE POINTS折抵 </view>
						<view class="hui_text main_size bold">${{orderInfo.RedeemAmount}}</view>
					</view>
					<view class="flexbetween margin_top">
						<view class="hei_text main_size bold">LINE 優惠券折抵  </view>
						<view class="hui_text main_size bold">${{orderInfo.StoreRedeemAmount}}</view>
					</view>
				</template>
			</view>
		</view>
		<view class="posibottom mainpadding flexright ffffff">
			<view class="flexright margin_top">
				<view class="listbtnhuang" v-show="orderInfo.status==0" @click.stop="phone(orderInfo)">
					{{orderInfo.is_guo==1?"已撥號":"撥號"}}
				</view>
				<!-- #ifdef APP-PLUS -->
				<!-- <view class="listbtnhuang margin_left2" v-show="orderInfo.status==0||orderInfo.status==1">推送</view> -->
				<!-- #endif -->
				<view class="listbtnhuang margin_left2" v-show="orderInfo.status==0 || orderInfo.status==1"
					@click.stop="cancelOrder(orderInfo.id)">取消</view>
				<view class="listbtnhuang margin_left2" v-show="orderInfo.status==1 && !ishave_zt"
					@click.stop="seating(orderInfo.id,orderInfo.ernum+orderInfo.oldnum+orderInfo.crnum)">完成
				</view>
				<view class="listbtnhuang margin_left2" v-show="orderInfo.status==1 && ishave_zt"
					@click.stop="seating(orderInfo.id,orderInfo.ernum+orderInfo.oldnum+orderInfo.crnum)">入座/服務
				</view>
				<view class="listbtnhuang margin_left2"
					v-show="orderInfo.status==2 && orderInfo.ordergood.order_type!=3" @click.stop="diancan(orderInfo)">
					點餐
				</view>
				<!-- 吃到飽點餐 -->
				<view class="listbtnhuang margin_left2" v-show="orderInfo.status==2 && orderInfo.ordergood.order_type==3"
					@click.stop="chidaobaodc(orderInfo.id,orderInfo.ordergood.cdbtc_id)">點餐
				</view>
				<view class="listbtnhuang margin_left2" v-show="orderInfo.status==2" @click.stop="xianjinsk(orderInfo)">
					收款</view>
			</view>
		</view>
		<u-modal :show="showConfirm" showCancelButton confirmColor="#ffb800" @cancel="showConfirm=false"
			confirmText="確認" cancelText="取消" @confirm="orderConfirm">
			<view class="slot-content color_ling text_weight text">
				{{text}}
			</view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageShow: false,
				listid: "",
				orderInfo: {},
				showConfirm: false,
				text: "你確定要放棄此訂單嗎？",
				id: "", //操作的订單id
				orderType: 0, //0取消 1跳过
				ishave_zt: true, //是否有使用，
				cdbjhsf_data: []
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getztList()
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			chidaobaodc(order_id,cdbtc_id){
				uni.setStorageSync("order_make_id", order_id)
				uni.navigateTo({
					url: "/pages/yuYueOrder/zizhucan?cdbtc_id=" + cdbtc_id
				})
			},
			async getDetail() { //確認放弃订單
				let res = await this.http.request('/api/Ordermake/deailOrdermake', 'POST', {
					id: this.listid
				})
				this.orderInfo = res.data
				if (this.orderInfo.ordergood.order_type == 3) {
					this.cdbjhsf_data = JSON.parse(res.data.cdbjhsf_data)
				}
				console.log(this.orderInfo.ordergood.opentype);
				this.pageShow = true
			},
			async getztList() { //使用列表
				let _this = this
				let res = await this.http.request('/api/shop/listtable', 'POST', {
					shop_id: uni.getStorageSync("shop_id"), //店鋪id
				})
				if (res.code == 1) {
					if (res.data.length == 0) {
						this.ishave_zt = false
					}
				}
			},
			phone(item) {
				let p = item.phone
				if (item.is_guo != 1) {
					this.makecall(item.id)
				}
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					// console.log(e)  //用catch(e)来捕获錯误{makePhoneCall:fail cancel}
				})
			},
			makecall(id) {
				this.http.request("/api/ordermake/makecall", "POST", {
					id
				}).then(res => {
					this.getDetail()
				})
			},

			skipOrder(id) { //跳过
				this.id = id
				this.text = "您確定要跳過此訂單嗎？"
				this.orderType = 1
				this.showConfirm = true
			},
			cancelOrder(id) { //取消
				this.id = id
				this.text = "您確定要取消此訂單嗎？"
				this.orderType = 0
				this.showConfirm = true
			},
			async orderConfirm() { //確認 取消订單/刪除订單
				let url = "",
					text = "";
				if (this.orderType == 0) {
					url = "/api/Ordermake/endOrdermake"
					text = "取消成功"
				} else {
					url = "/api/Ordermake/guoOrdermake"
					text = "跳過成功"
				}
				let _this = this
				let res = await this.http.request(url, 'POST', {
					id: this.id
				})
				if (res.code == 1) {
					this.http.toast(text)
					this.showConfirm = false
					this.getDetail()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			seating(id, count) { //入座/服務
				if (this.ishave_zt == false) {
					this.http.request('/api/Ordermake/addOrdermake', 'POST', {
						ordermark_id: id, //订單id
						table_id: 0,
						order_type: 2,
					}).then(res => {
						if (res.code == 1) {
							this.getDetail()
						} else {
							this.http.toast(res.msg)
						}
					})
					return false
				}
				uni.navigateTo({
					url: `./selectDesk?id=${id}&count=${count}`
				})
			},
			diancan(item) {
				uni.setStorageSync("order_goods_id", item.order_goods_id)
				uni.navigateTo({
					url: "/pages/callOutOrder/xuanzefw?orderly=1"
				})
			},
			xianjinsk(item) {
				// this.http.modal('', '請確認是否完成現金收款', true, (res) => {
				// 	if (res) {
				// 		this.http.request('/api/ordermake/endmarkmoney', 'POST', {
				// 			id: item.order_goods_id,
				// 		}).then(res => {
				// 			if (res.code == 1) {
				// 				this.http.toast("現金收款完成")
				// 				this.getDetail()
				// 			} else {
				// 				this.http.toast(res.msg)
				// 			}
				// 		})
				// 	}
				// })
				uni.navigateTo({
					url: "/pages/yuYueOrder/yuyuesk?total_price=" + item.ordergood.zhuimoney + "&id=" + item.id
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.beihuolable {
		background-color: #fff3e6;
		padding: 5rpx 10rpx;
		border: 1rpx solid #FF8505;
	}

	.posibottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
	}
</style>
<style lang="scss" scoped>
	.margin_right3 {
		margin-right: 30rpx;
	}

	.goodsImg {
		width: 157rpx;
		height: 157rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}

		.shipment {
			// width: 71rpx;
			// height: 30rpx;
			// line-height: 30rpx;
			padding: 4rpx;
			box-sizing: border-box;
			text-align: center;
			background: #13C463;
			border-radius: 14rpx 0rpx 14rpx 0rpx;
			font-size: 18rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			position: absolute;
			left: 0;
			top: 0;
		}
	}

	.listleftimg1 {
		width: 150rpx;
		min-width: 150rpx;
		height: 150rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.bghuang {
		background-color: #feb800;
		padding: 15rpx 30rpx;
	}

	::v-deep.u-tabs__wrapper__nav__item {
		flex: 1;
		white-space: nowrap;
	}
</style>